<%@ include file="/html/library/init.jsp" %>

This is the list of books

<%
	List<Book> books = (List<Book>)renderRequest.getAttribute("BOOKS");	

	if (Validator.isNull(books)) {
		int count = BookLocalServiceUtil.getBooksCount();
		books = BookLocalServiceUtil.getBooks(0, count);
	}
%>

<%-- 
<table border="1">
	<tr>
		<th>Book Title</th>
		<th>Book Author</th>
		<th>Date Added</th>
	</tr>
	
	<% 	
		for (Book book : books) {
			%>
				<tr>
					<td><%= book.getBookTitle() %></td>
					<td><%= book.getAuthor() %></td>
					<td><fmt:formatDate value="<%= book.getDateAdded() %>" pattern="dd/MMM/yyyy"/>
				</tr>
			<%	
		}
	%>
</table>
--%>

<%
	PortletURL deleteBookURL = renderResponse.createActionURL();
	deleteBookURL.setParameter(ActionRequest.ACTION_NAME, "deleteBook");
	
	PortletURL iteratorURL = renderResponse.createRenderURL();
	iteratorURL.setParameter("jspPage", "/html/library/list.jsp");
	
	deleteBookURL.setParameter("redirectURL", iteratorURL.toString());
	
	int noOfItems = GetterUtil.getInteger(((String)portletSession.getAttribute("noOfItems", PortletSession.APPLICATION_SCOPE)), 2);
%>

<liferay-ui:search-container delta="<%= noOfItems %>" emptyResultsMessage="No items to display" iteratorURL="<%= iteratorURL %>">
	<liferay-ui:search-container-results 
		results="<%= ListUtil.subList(books, searchContainer.getStart(), searchContainer.getEnd()) %>" 
		total="<%= books.size() %>" />
	<liferay-ui:search-container-row className="com.library.slayer.model.Book" modelVar="book" >
		<liferay-ui:search-container-column-text property="bookTitle" name="Book Title"/>
		<liferay-ui:search-container-column-text property="author" orderable="true"/>
		<liferay-ui:search-container-column-text name="Date Added">
			<fmt:formatDate value="<%= book.getDateAdded() %>" pattern="dd/MMM/yyyy"/>
		</liferay-ui:search-container-column-text>
		
		<liferay-ui:search-container-column-text name="Delete">
			<% deleteBookURL.setParameter("bookId", String.valueOf(book.getBookId())); %>
			<a href="<%= deleteBookURL.toString() %>">delete</a>
		</liferay-ui:search-container-column-text>
		
		<liferay-ui:search-container-column-jsp align="right" name="Actions" path="/html/library/book-actions.jsp" />
				
	</liferay-ui:search-container-row>	
	
	<liferay-ui:search-iterator searchContainer="<%= searchContainer %>" />
</liferay-ui:search-container>

<br/><a href="<portlet:renderURL/>">&laquo; Go Back</a>

<c:if test="<%= books.size() % 2 == 0 %>">There are even number of books in this library</c:if>